package com.itheima.HomeWork.homework;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Demo {
    public static void main(String[] args) throws IOException, InterruptedException {
        /*FileReader fr = new FileReader("E:\\img1\\hero.txt", Charset.forName("GBK"));
        BufferedReader br = new BufferedReader(fr);
        String tou = br.readLine();
        String lne;
        ArrayList<Yingxiong> yingxiongs = new ArrayList<>();
        while ((lne = br.readLine()) != null) {
            String[] split = lne.split(",+");
            Yingxiong yx = new Yingxiong(split[0], split[1], split[2], split[3]);
            yingxiongs.add(yx);
        }
        br.close();
        Collections.sort(yingxiongs, new Comparator<Yingxiong>() {
            @Override
            public int compare(Yingxiong o1, Yingxiong o2) {
                return Double.compare(o2.getJk(), o1.getJk());
            }
        });
//        System.out.println(yingxiongs);
        FileWriter fileWriter = new FileWriter("E:\\img1\\hero.txt", Charset.forName("GBK"));
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write("姓名\t生存\t攻击\t效果\t新手");
        bufferedWriter.newLine();
        for (Yingxiong yingxiong : yingxiongs) {
            bufferedWriter.write(yingxiong.getName() + "\t" + yingxiong.getSc() + "\t" + yingxiong.getGj() + "\t" + yingxiong.getXg() + "\t" + yingxiong.getJk());
            bufferedWriter.newLine();
        }
        bufferedWriter.close();
        fileWriter.close();*/
        BufferedReader br = new BufferedReader(new FileReader("E:\\img1\\hero.txt", Charset.forName("GBK")));
        String lne;
        String t = br.readLine();
        ArrayList<Yingxiong> yingxiongs = new ArrayList<>();
        while ((lne=br.readLine())!=null){
            String[] split = lne.split(",+");
            Yingxiong yingxiong = new Yingxiong(split[0], split[1], split[2], split[3]);
            yingxiongs.add(yingxiong);
        }
        br.close();
        Collections.sort(yingxiongs, new Comparator<Yingxiong>() {
            @Override
            public int compare(Yingxiong o1, Yingxiong o2) {
                return Double.compare(o1.getJk(),o2.getJk());
            }
        });
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\img1\\hero.txt", Charset.forName("GBK")));
        bw.write("0 0 0 0 0");
        bw.newLine();
        for (Yingxiong yingxiong : yingxiongs) {
            bw.write(yingxiong.getName() + "\t" + yingxiong.getSc() + "\t" + yingxiong.getGj() + "\t" + yingxiong.getXg() + "\t" + yingxiong.getJk());
            bw.newLine();
        }
        bw.close();
    }
}

